@page "/docio/word-to-odt"
@inject Microsoft.JSInterop.IJSRuntime JS
@using System.IO
@using Microsoft.AspNetCore.Http
@using Syncfusion.Blazor.Buttons
@using BlazorDemos.Data.FileFormats.DocIO
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment
@inherits SampleBaseComponent;

<SampleDescription>
   <p style="font-size:16px">This sample demonstrates how to convert the Word document to ODT using Essential DocIO.</p> 
</SampleDescription>
<ActionDescription>
   <p style="font-size:16px">DocIO provides support to convert the Word document to Open Document Text format.</p>&nbsp;<p style="font-size:16px">More information about ODT conversion can be found in this <a href="https://help.syncfusion.com/file-formats/docio/word-to-odt">documentation</a> section.</p>
</ActionDescription>

<div class="control-section">
    <p style="font-size:16px">Click the button to view the resultant ODT document generated by Essential DocIO.</p>
    <div class="button-section">
        <div id="button-control">
            <div class="row">
                <div>
                    <SfButton @onclick="ViewTemplate">View Template</SfButton>&nbsp;
                    <SfButton @onclick="ConvertToODT">Convert to ODT</SfButton>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .control-section .row {
        margin: 10px 0;
    }
</style>

@code {
    MemoryStream documentStream;

    /// <summary>
    /// Create and download the simple Word document
    /// </summary>
    public async Task ConvertToODT(MouseEventArgs args)
    {
        WordToODTService service = new WordToODTService(hostingEnvironment);
        documentStream = service.WordToODT("Generate Document");
        await JS.SaveAs("WordToODT.odt", documentStream.ToArray());
    }
    /// <summary>
    /// Create and download the template Word document
    /// </summary>
    public async Task ViewTemplate(MouseEventArgs args)
    {
        WordToODTService service = new WordToODTService(hostingEnvironment);
        documentStream = service.WordToODT("View Template");
        await JS.SaveAs("Word to ODT.docx", documentStream.ToArray());
    }
}